package com.yipinhouse.backstage.app.apiImpl;

import cn.hutool.core.bean.BeanUtil;
import com.yipinhouse.backstage.client.HouseManageWebClient;
import com.yipinhouse.backstage.client.param.*;
import com.yipinhouse.common.result.Result;
import com.yipinhouse.house.client.*;
import com.yipinhouse.house.client.param.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Slf4j
@RequestMapping("backstage")
public class HouseManageWebApiImpl implements HouseManageWebClient {

    @Resource
    private NewHouseQueryClient newHouseQueryClient;

    @Resource
    private PremisesQueryClient premisesQueryClient;

    @Resource
    private ResoldHouseManageClient resoldHouseManageClient;

    @Resource
    private ResoldApartmentManageClient resoldApartmentManageClient;

    @Resource
    private ApartmentClient apartmentClient;

    @Resource
    private HouseRequestManageClient houseRequestManageClient;

    @Override
    public Result insertPremises(InsertPremisesWebParam param) {
        InsertPremisesParam insertPremisesParam = BeanUtil.copyProperties(param, InsertPremisesParam.class);
        Result result = premisesQueryClient.insertPremises(insertPremisesParam);
        return result;
    }

    @Override
    public Result updatePremises(UpdatePremisesWebParam param) {
        UpdatePremisesParam updatePremisesParam = BeanUtil.copyProperties(param, UpdatePremisesParam.class);
        Result result = premisesQueryClient.updatePremises(updatePremisesParam);
        return result;
    }

    @Override
    public Result insertApartment(InsertApartmentWebParam param) throws Exception {
        log.info("生成的参数为：{}",param);
        InsertApartmentParam insertApartmentParam = BeanUtil.copyProperties(param, InsertApartmentParam.class);
        log.info("copy后的参数为:{}",insertApartmentParam);
        Result result = apartmentClient.insertApartment(insertApartmentParam);
        return result;
    }

    @Override
    public Result deletePremises(Integer id) {
        Result result = premisesQueryClient.deletePremises(id);
        return result;
    }

    @Override
    public Result insertNewHouse(InsertNewHouseWebParam param) {
        InsertNewHouseParam insertNewHouseParam = BeanUtil.copyProperties(param, InsertNewHouseParam.class);
        Result result = newHouseQueryClient.insertNewHouse(insertNewHouseParam);
        return result;
    }

    @Override
    public Result updateNewHouse(UpdateNewHouseWebParam param) {
        UpdateNewHouseParam updateNewHouseParam = BeanUtil.copyProperties(param, UpdateNewHouseParam.class);
        Result result = newHouseQueryClient.updateNewHouse(updateNewHouseParam);
        return result;
    }

    @Override
    public Result deleteNewHouse(Integer id) {
        Result result = newHouseQueryClient.deleteNewHouse(id);
        return result;
    }

    @Override
    public Result onSealHouse(Integer houseId) {
        Result result = newHouseQueryClient.onSealHouse(houseId);
        return result;
    }


    @Override
    public Result resoldOnSaleHouse(Integer houseId) {
        Result result = resoldHouseManageClient.onSaleHouse(houseId);
        return result;
    }

    @Override
    public Result resoldPullOffShelf(Integer houseId) {
        Result result = resoldHouseManageClient.pullOffShelf(houseId);
        return result;
    }


    @Override
    public Result aOnSaleHouse(Integer houseId) {
        Result result = resoldApartmentManageClient.onSaleHouse(houseId);
        return result;
    }

    @Override
    public Result aPullOffShelf(Integer houseId) {
        Result result = resoldApartmentManageClient.pullOffShelf(houseId);
        return result;
    }

    @Override
    public Result passHouseRequest(Integer requestId) {
        log.info("同意房源上传：参数：{}",requestId);
        Result result = houseRequestManageClient.passHouseRequest(requestId);
        return result;
    }

    @Override
    public Result rejectHouseRequest(RejectHouseWebRequestParam param) {
        log.info("拒绝房源上传：参数：{}",param);
        RejectHouseRequestParam rejectHouseRequestParam = BeanUtil.toBean(param, RejectHouseRequestParam.class);
        Result result = houseRequestManageClient.rejectHouseRequest(rejectHouseRequestParam);
        return result;
    }
}
